﻿using Domain.Roles.ValueObjects;
using Shared.Domain.Abstructs;
using Shared.Domain.Interface;

namespace Domain.Roles.Entities
{
    public partial class Role : BaseEntity<Guid>, IAggregateRoot
    {
        /// <summary>
        /// 角色名称
        /// </summary>
        public RoleName RoleName { get; private set; }

        private Role()
        {

        }

        private Role(Guid id, IEnumerable<string> signList, RoleName roleName, bool enable, string? description) : base(id)
        {
            RoleName = roleName;
            Enable = enable;
            this._permissionSigns = [.. signList];
            Description = description ?? string.Empty;
        }

        /// <summary>
        /// 创建新角色
        /// </summary>
        /// <param name="roleName"></param>
        /// <param name="permissions"></param>
        /// <param name="enable"></param>
        /// <param name="description"></param>
        /// <returns></returns>
        public static Role Create(RoleName roleName, IEnumerable<string> signList, bool? enable, string? description)
        {
            return new(Guid.NewGuid(), signList, roleName, enable ?? false, description);
        }

        #region 领域事件集合
        private readonly List<IDomainEvent> _domainEvents = [];

        public IReadOnlyList<IDomainEvent> DomainEvents => _domainEvents;
        #endregion

        #region 角色权限集合
        private IList<string> _permissionSigns;
        public IReadOnlyCollection<string> PermissionSigns => _permissionSigns.AsReadOnly();
        #endregion

        public bool Enable { get; set; }

        public string Description { get; set; } = string.Empty;
    }
}
